package com.javafactroy.kunlong.test.redis;

import com.javafactroy.kunlong.DbAgent;
import com.javafactroy.kunlong.data.dao.mysql.MysqlTablesMapper;
import com.javafactroy.kunlong.data.entity.mysql.MysqlTables;
import com.javafactroy.kunlong.common.utils.CommonUtils;
import com.javafactroy.kunlong.common.utils.RedisApiUtil;
import com.javafactroy.kunlong.common.utils.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.BoundHashOperations;
import org.springframework.data.redis.core.BoundListOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import java.util.List;
import java.util.Set;
@SpringBootTest(classes = {DbAgent.class}, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ExtendWith(SpringExtension.class)
@Slf4j
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@TestMethodOrder(MethodOrderer.MethodName.class)
public class TestSpringRedis {
    @Autowired
    MysqlTablesMapper mysqlTablesMapper;
    @Autowired
    StringRedisTemplate stringRedisTemplate;

    @Autowired
    RedisUtil redisUtil;
    @Autowired
    RedisApiUtil redisApiUtil;

    @Autowired
    private RedisTemplate redisTemplate;

    @Test
    public void test001_tbl() {

        List<MysqlTables> tables = mysqlTablesMapper.select(new MysqlTables().setDbName("platform"));
        log.info("tabels={}", CommonUtils.toJSONString(tables));
        redisUtil.put("tables", CommonUtils.toJSONString(tables));
        log.info("t={}", redisUtil.get("tables"));

    }

    //@Autowired
    //private StringRedisTemplate stringRedisTemplate;

    @Test
    public void test002_redis() {
        this.stringRedisTemplate.opsForValue().set("1", "2");
        String s = stringRedisTemplate.opsForValue().get("1");
        log.info("s={}", s);
        BoundListOperations listOperations = stringRedisTemplate.boundListOps("aaaa");//set(2, "21");
        listOperations.rightPush("1111");
        listOperations.rightPush("1111222");
        log.info("{}", listOperations.range(0, 2));


        BoundHashOperations hashOperations = redisTemplate.boundHashOps("1");
        hashOperations.put("name", 111);
        hashOperations.put("age", 78);

        Set keys = hashOperations.keys();
        log.info("keys={}", keys);

    }


}
